import { getUserID, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';
import { useCallback, useMemo } from 'react';
import { AssetAcquisitionManageAPI } from '../common/type';
import { ApplyManageTab } from '../mconfig';
import { getBaseUrl } from '@/services/urlconst';

let baseUrl = getBaseUrl();

const MaterialServices = (materialCallback: (res: any) => void) => {
  /***管理页获取数据方法**/
  const { tableProps, data, loading, run } = useRequest(
    (reqParams: any) => {
      let PostParams = {
        // current: 1,
        // pageSize: 10,
        sort: 'id',
        order: 'desc',
        ...reqParams,
      };
      const reqbody = PostParams;
      let reqUrl = `${baseUrl}/assetStorage/materialList`;
      /***发起请求数据接口**/
      return requestFunComponFiex('POST', reqUrl, reqbody);
    },
    {
      manual: true,
      paginated: true,
      // defaultPageSize: 10,
      onSuccess: (res) => {
        materialCallback(res);
      },
    },
  );

  /***重新请求的方法**/
  const reloadRequest = useCallback((reqParams: AssetAcquisitionManageAPI.IMaterialTableRequestType | any) => {
    run({ ...reqParams });
  }, []);

  /***页面数据及分页信息**/
  const tableValues = useMemo(() => {
    return {
      data,
    };
  }, [data, tableProps]);
  return {
    loading,
    reloadRequest,
    ...tableValues, //页面列表值
  };
};

export { MaterialServices };
